Imports cmplib01
Imports System.Drawing.Drawing2D
Imports cmplib01.CampaignerGameData

Public Class ctlEndOfCombatPhase
    Inherits System.Windows.Forms.UserControl

    Public Event ApplyCombatResults()

    Private ptrGameData As CampaignerGameData
    Private ptrSelectedBattle As Battle
    Private m_MapData As FMPLib01.FlexMapData
    Private ptrMapBmp As Bitmap

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlCombatsTitle As System.Windows.Forms.Panel
    Friend WithEvents lblCombats As System.Windows.Forms.Label
    Friend WithEvents imgCheckNoCheck As System.Windows.Forms.ImageList
    Friend WithEvents pnlSelectedBattle As System.Windows.Forms.Panel
    Friend WithEvents lblCombatName As System.Windows.Forms.Label
    Friend WithEvents optUnresolved As System.Windows.Forms.RadioButton
    Friend WithEvents optAttackerMarginalVictory As System.Windows.Forms.RadioButton
    Friend WithEvents optAttackerVictory As System.Windows.Forms.RadioButton
    Friend WithEvents optDraw As System.Windows.Forms.RadioButton
    Friend WithEvents optDefenderMarginalVictory As System.Windows.Forms.RadioButton
    Friend WithEvents optDefenderVictory As System.Windows.Forms.RadioButton
    Friend WithEvents imlChitIcons As System.Windows.Forms.ImageList
    Friend WithEvents btnApply As System.Windows.Forms.Button
    Friend WithEvents picBattleArea As System.Windows.Forms.PictureBox
    Friend WithEvents lblTerrain As System.Windows.Forms.Label
    Friend WithEvents lblDefensiveValue As System.Windows.Forms.Label
    Friend WithEvents lblTerrainDescription As System.Windows.Forms.Label
    Friend WithEvents lblDescriptionLabel As System.Windows.Forms.Label
    Friend WithEvents cboActiveBattle As System.Windows.Forms.ComboBox
    Friend WithEvents lblSelectBattle As System.Windows.Forms.Label
    Friend WithEvents basAttackerAssets As ctlBattleAssets
    Friend WithEvents pnlArea As System.Windows.Forms.Panel
    Friend WithEvents pnlAssets As System.Windows.Forms.Panel
    Friend WithEvents splAssetSplitter As System.Windows.Forms.Splitter
    Friend WithEvents basDefenderAssets As ctlBattleAssets
    Friend WithEvents tmrRedrawBattlemap As System.Windows.Forms.Timer
    Friend WithEvents btnCombatSummary As System.Windows.Forms.Button
    Friend WithEvents optAttackerBreakthrough As System.Windows.Forms.RadioButton
    Friend WithEvents optDefenderBreakout As System.Windows.Forms.RadioButton
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ctlEndOfCombatPhase))
        Me.pnlCombatsTitle = New System.Windows.Forms.Panel
        Me.lblCombats = New System.Windows.Forms.Label
        Me.btnApply = New System.Windows.Forms.Button
        Me.imgCheckNoCheck = New System.Windows.Forms.ImageList(Me.components)
        Me.pnlSelectedBattle = New System.Windows.Forms.Panel
        Me.optAttackerBreakthrough = New System.Windows.Forms.RadioButton
        Me.optDefenderBreakout = New System.Windows.Forms.RadioButton
        Me.btnCombatSummary = New System.Windows.Forms.Button
        Me.optDefenderVictory = New System.Windows.Forms.RadioButton
        Me.optDefenderMarginalVictory = New System.Windows.Forms.RadioButton
        Me.optDraw = New System.Windows.Forms.RadioButton
        Me.optAttackerVictory = New System.Windows.Forms.RadioButton
        Me.optAttackerMarginalVictory = New System.Windows.Forms.RadioButton
        Me.optUnresolved = New System.Windows.Forms.RadioButton
        Me.lblCombatName = New System.Windows.Forms.Label
        Me.imlChitIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.picBattleArea = New System.Windows.Forms.PictureBox
        Me.pnlArea = New System.Windows.Forms.Panel
        Me.lblDescriptionLabel = New System.Windows.Forms.Label
        Me.lblTerrainDescription = New System.Windows.Forms.Label
        Me.lblDefensiveValue = New System.Windows.Forms.Label
        Me.lblTerrain = New System.Windows.Forms.Label
        Me.cboActiveBattle = New System.Windows.Forms.ComboBox
        Me.lblSelectBattle = New System.Windows.Forms.Label
        Me.basAttackerAssets = New ctlBattleAssets
        Me.pnlAssets = New System.Windows.Forms.Panel
        Me.basDefenderAssets = New ctlBattleAssets
        Me.splAssetSplitter = New System.Windows.Forms.Splitter
        Me.tmrRedrawBattlemap = New System.Windows.Forms.Timer(Me.components)
        Me.pnlCombatsTitle.SuspendLayout()
        Me.pnlSelectedBattle.SuspendLayout()
        CType(Me.picBattleArea, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.pnlArea.SuspendLayout()
        Me.pnlAssets.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlCombatsTitle
        '
        Me.pnlCombatsTitle.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlCombatsTitle.Controls.Add(Me.lblCombats)
        Me.pnlCombatsTitle.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlCombatsTitle.Location = New System.Drawing.Point(0, 0)
        Me.pnlCombatsTitle.Name = "pnlCombatsTitle"
        Me.pnlCombatsTitle.Size = New System.Drawing.Size(707, 44)
        Me.pnlCombatsTitle.TabIndex = 1
        '
        'lblCombats
        '
        Me.lblCombats.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCombats.Location = New System.Drawing.Point(24, 8)
        Me.lblCombats.Name = "lblCombats"
        Me.lblCombats.Size = New System.Drawing.Size(416, 22)
        Me.lblCombats.TabIndex = 0
        Me.lblCombats.Text = "Combat Resolution"
        '
        'btnApply
        '
        Me.btnApply.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnApply.BackColor = System.Drawing.Color.Yellow
        Me.btnApply.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnApply.Image = CType(resources.GetObject("btnApply.Image"), System.Drawing.Image)
        Me.btnApply.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnApply.Location = New System.Drawing.Point(8, 344)
        Me.btnApply.Name = "btnApply"
        Me.btnApply.Size = New System.Drawing.Size(347, 24)
        Me.btnApply.TabIndex = 1
        Me.btnApply.Text = "End Combat Resolution Phase"
        Me.btnApply.UseVisualStyleBackColor = False
        '
        'imgCheckNoCheck
        '
        Me.imgCheckNoCheck.ImageStream = CType(resources.GetObject("imgCheckNoCheck.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imgCheckNoCheck.TransparentColor = System.Drawing.Color.Transparent
        Me.imgCheckNoCheck.Images.SetKeyName(0, "")
        Me.imgCheckNoCheck.Images.SetKeyName(1, "")
        Me.imgCheckNoCheck.Images.SetKeyName(2, "")
        Me.imgCheckNoCheck.Images.SetKeyName(3, "")
        Me.imgCheckNoCheck.Images.SetKeyName(4, "")
        Me.imgCheckNoCheck.Images.SetKeyName(5, "")
        Me.imgCheckNoCheck.Images.SetKeyName(6, "")
        Me.imgCheckNoCheck.Images.SetKeyName(7, "")
        '
        'pnlSelectedBattle
        '
        Me.pnlSelectedBattle.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlSelectedBattle.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlSelectedBattle.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlSelectedBattle.Controls.Add(Me.optAttackerBreakthrough)
        Me.pnlSelectedBattle.Controls.Add(Me.optDefenderBreakout)
        Me.pnlSelectedBattle.Controls.Add(Me.btnCombatSummary)
        Me.pnlSelectedBattle.Controls.Add(Me.optDefenderVictory)
        Me.pnlSelectedBattle.Controls.Add(Me.optDefenderMarginalVictory)
        Me.pnlSelectedBattle.Controls.Add(Me.optDraw)
        Me.pnlSelectedBattle.Controls.Add(Me.optAttackerVictory)
        Me.pnlSelectedBattle.Controls.Add(Me.optAttackerMarginalVictory)
        Me.pnlSelectedBattle.Controls.Add(Me.optUnresolved)
        Me.pnlSelectedBattle.Controls.Add(Me.lblCombatName)
        Me.pnlSelectedBattle.Controls.Add(Me.btnApply)
        Me.pnlSelectedBattle.Location = New System.Drawing.Point(328, 224)
        Me.pnlSelectedBattle.Name = "pnlSelectedBattle"
        Me.pnlSelectedBattle.Size = New System.Drawing.Size(370, 376)
        Me.pnlSelectedBattle.TabIndex = 4
        '
        'optAttackerBreakthrough
        '
        Me.optAttackerBreakthrough.Appearance = System.Windows.Forms.Appearance.Button
        Me.optAttackerBreakthrough.BackColor = System.Drawing.Color.DarkSalmon
        Me.optAttackerBreakthrough.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optAttackerBreakthrough.Image = CType(resources.GetObject("optAttackerBreakthrough.Image"), System.Drawing.Image)
        Me.optAttackerBreakthrough.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optAttackerBreakthrough.Location = New System.Drawing.Point(8, 183)
        Me.optAttackerBreakthrough.Name = "optAttackerBreakthrough"
        Me.optAttackerBreakthrough.Size = New System.Drawing.Size(168, 39)
        Me.optAttackerBreakthrough.TabIndex = 8
        Me.optAttackerBreakthrough.Text = "Attacker Breakthrough"
        Me.optAttackerBreakthrough.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optAttackerBreakthrough.UseVisualStyleBackColor = False
        '
        'optDefenderBreakout
        '
        Me.optDefenderBreakout.Appearance = System.Windows.Forms.Appearance.Button
        Me.optDefenderBreakout.BackColor = System.Drawing.Color.DarkSalmon
        Me.optDefenderBreakout.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optDefenderBreakout.Image = CType(resources.GetObject("optDefenderBreakout.Image"), System.Drawing.Image)
        Me.optDefenderBreakout.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optDefenderBreakout.Location = New System.Drawing.Point(182, 107)
        Me.optDefenderBreakout.Name = "optDefenderBreakout"
        Me.optDefenderBreakout.Size = New System.Drawing.Size(168, 39)
        Me.optDefenderBreakout.TabIndex = 9
        Me.optDefenderBreakout.Text = "Defender Breakout"
        Me.optDefenderBreakout.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optDefenderBreakout.UseVisualStyleBackColor = False
        '
        'btnCombatSummary
        '
        Me.btnCombatSummary.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnCombatSummary.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnCombatSummary.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCombatSummary.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnCombatSummary.Location = New System.Drawing.Point(8, 312)
        Me.btnCombatSummary.Name = "btnCombatSummary"
        Me.btnCombatSummary.Size = New System.Drawing.Size(168, 24)
        Me.btnCombatSummary.TabIndex = 7
        Me.btnCombatSummary.Text = "Show Summary"
        Me.btnCombatSummary.UseVisualStyleBackColor = False
        '
        'optDefenderVictory
        '
        Me.optDefenderVictory.Appearance = System.Windows.Forms.Appearance.Button
        Me.optDefenderVictory.BackColor = System.Drawing.Color.DarkSalmon
        Me.optDefenderVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optDefenderVictory.Image = CType(resources.GetObject("optDefenderVictory.Image"), System.Drawing.Image)
        Me.optDefenderVictory.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optDefenderVictory.Location = New System.Drawing.Point(182, 145)
        Me.optDefenderVictory.Name = "optDefenderVictory"
        Me.optDefenderVictory.Size = New System.Drawing.Size(168, 39)
        Me.optDefenderVictory.TabIndex = 5
        Me.optDefenderVictory.Text = "Defender Victory"
        Me.optDefenderVictory.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optDefenderVictory.UseVisualStyleBackColor = False
        '
        'optDefenderMarginalVictory
        '
        Me.optDefenderMarginalVictory.Appearance = System.Windows.Forms.Appearance.Button
        Me.optDefenderMarginalVictory.BackColor = System.Drawing.Color.DarkSalmon
        Me.optDefenderMarginalVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optDefenderMarginalVictory.Image = CType(resources.GetObject("optDefenderMarginalVictory.Image"), System.Drawing.Image)
        Me.optDefenderMarginalVictory.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optDefenderMarginalVictory.Location = New System.Drawing.Point(182, 183)
        Me.optDefenderMarginalVictory.Name = "optDefenderMarginalVictory"
        Me.optDefenderMarginalVictory.Size = New System.Drawing.Size(168, 39)
        Me.optDefenderMarginalVictory.TabIndex = 6
        Me.optDefenderMarginalVictory.Text = "Defender Marginal Victory"
        Me.optDefenderMarginalVictory.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optDefenderMarginalVictory.UseVisualStyleBackColor = False
        '
        'optDraw
        '
        Me.optDraw.Appearance = System.Windows.Forms.Appearance.Button
        Me.optDraw.BackColor = System.Drawing.Color.DarkSalmon
        Me.optDraw.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optDraw.Image = CType(resources.GetObject("optDraw.Image"), System.Drawing.Image)
        Me.optDraw.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optDraw.Location = New System.Drawing.Point(8, 74)
        Me.optDraw.Name = "optDraw"
        Me.optDraw.Size = New System.Drawing.Size(168, 24)
        Me.optDraw.TabIndex = 4
        Me.optDraw.Text = "Draw"
        Me.optDraw.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optDraw.UseVisualStyleBackColor = False
        '
        'optAttackerVictory
        '
        Me.optAttackerVictory.Appearance = System.Windows.Forms.Appearance.Button
        Me.optAttackerVictory.BackColor = System.Drawing.Color.DarkSalmon
        Me.optAttackerVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optAttackerVictory.Image = CType(resources.GetObject("optAttackerVictory.Image"), System.Drawing.Image)
        Me.optAttackerVictory.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optAttackerVictory.Location = New System.Drawing.Point(8, 107)
        Me.optAttackerVictory.Name = "optAttackerVictory"
        Me.optAttackerVictory.Size = New System.Drawing.Size(168, 39)
        Me.optAttackerVictory.TabIndex = 2
        Me.optAttackerVictory.Text = "Attacker Victory"
        Me.optAttackerVictory.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optAttackerVictory.UseVisualStyleBackColor = False
        '
        'optAttackerMarginalVictory
        '
        Me.optAttackerMarginalVictory.Appearance = System.Windows.Forms.Appearance.Button
        Me.optAttackerMarginalVictory.BackColor = System.Drawing.Color.DarkSalmon
        Me.optAttackerMarginalVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optAttackerMarginalVictory.Image = CType(resources.GetObject("optAttackerMarginalVictory.Image"), System.Drawing.Image)
        Me.optAttackerMarginalVictory.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optAttackerMarginalVictory.Location = New System.Drawing.Point(8, 145)
        Me.optAttackerMarginalVictory.Name = "optAttackerMarginalVictory"
        Me.optAttackerMarginalVictory.Size = New System.Drawing.Size(168, 39)
        Me.optAttackerMarginalVictory.TabIndex = 3
        Me.optAttackerMarginalVictory.Text = "Attacker Marginal Victory Of the Heart"
        Me.optAttackerMarginalVictory.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optAttackerMarginalVictory.UseVisualStyleBackColor = False
        '
        'optUnresolved
        '
        Me.optUnresolved.Appearance = System.Windows.Forms.Appearance.Button
        Me.optUnresolved.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.optUnresolved.Checked = True
        Me.optUnresolved.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.optUnresolved.Image = CType(resources.GetObject("optUnresolved.Image"), System.Drawing.Image)
        Me.optUnresolved.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.optUnresolved.Location = New System.Drawing.Point(8, 40)
        Me.optUnresolved.Name = "optUnresolved"
        Me.optUnresolved.Size = New System.Drawing.Size(168, 24)
        Me.optUnresolved.TabIndex = 1
        Me.optUnresolved.TabStop = True
        Me.optUnresolved.Text = "Unresolved"
        Me.optUnresolved.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.optUnresolved.UseVisualStyleBackColor = False
        '
        'lblCombatName
        '
        Me.lblCombatName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblCombatName.BackColor = System.Drawing.Color.WhiteSmoke
        Me.lblCombatName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblCombatName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCombatName.Location = New System.Drawing.Point(-1, -1)
        Me.lblCombatName.Name = "lblCombatName"
        Me.lblCombatName.Size = New System.Drawing.Size(370, 25)
        Me.lblCombatName.TabIndex = 0
        Me.lblCombatName.Text = "Snarsnik vs 115th Mechanized"
        Me.lblCombatName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'imlChitIcons
        '
        Me.imlChitIcons.ImageStream = CType(resources.GetObject("imlChitIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlChitIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlChitIcons.Images.SetKeyName(0, "")
        Me.imlChitIcons.Images.SetKeyName(1, "")
        Me.imlChitIcons.Images.SetKeyName(2, "")
        Me.imlChitIcons.Images.SetKeyName(3, "")
        Me.imlChitIcons.Images.SetKeyName(4, "")
        Me.imlChitIcons.Images.SetKeyName(5, "")
        '
        'picBattleArea
        '
        Me.picBattleArea.BackColor = System.Drawing.Color.Gainsboro
        Me.picBattleArea.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picBattleArea.Location = New System.Drawing.Point(8, 8)
        Me.picBattleArea.Name = "picBattleArea"
        Me.picBattleArea.Size = New System.Drawing.Size(144, 120)
        Me.picBattleArea.TabIndex = 8
        Me.picBattleArea.TabStop = False
        '
        'pnlArea
        '
        Me.pnlArea.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlArea.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlArea.Controls.Add(Me.lblDescriptionLabel)
        Me.pnlArea.Controls.Add(Me.lblTerrainDescription)
        Me.pnlArea.Controls.Add(Me.lblDefensiveValue)
        Me.pnlArea.Controls.Add(Me.lblTerrain)
        Me.pnlArea.Controls.Add(Me.picBattleArea)
        Me.pnlArea.Location = New System.Drawing.Point(8, 80)
        Me.pnlArea.Name = "pnlArea"
        Me.pnlArea.Size = New System.Drawing.Size(689, 136)
        Me.pnlArea.TabIndex = 9
        '
        'lblDescriptionLabel
        '
        Me.lblDescriptionLabel.Location = New System.Drawing.Point(160, 73)
        Me.lblDescriptionLabel.Name = "lblDescriptionLabel"
        Me.lblDescriptionLabel.Size = New System.Drawing.Size(128, 16)
        Me.lblDescriptionLabel.TabIndex = 12
        Me.lblDescriptionLabel.Text = "Description"
        '
        'lblTerrainDescription
        '
        Me.lblTerrainDescription.Location = New System.Drawing.Point(160, 97)
        Me.lblTerrainDescription.Name = "lblTerrainDescription"
        Me.lblTerrainDescription.Size = New System.Drawing.Size(448, 31)
        Me.lblTerrainDescription.TabIndex = 11
        Me.lblTerrainDescription.Text = "(Hills): Rolling hills with occasional tree coverage. (Light Woods): Lightly wood" & _
            "ed area."
        '
        'lblDefensiveValue
        '
        Me.lblDefensiveValue.Location = New System.Drawing.Point(160, 49)
        Me.lblDefensiveValue.Name = "lblDefensiveValue"
        Me.lblDefensiveValue.Size = New System.Drawing.Size(128, 23)
        Me.lblDefensiveValue.TabIndex = 10
        Me.lblDefensiveValue.Text = "Defensive Value: 0"
        '
        'lblTerrain
        '
        Me.lblTerrain.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblTerrain.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblTerrain.Location = New System.Drawing.Point(160, 8)
        Me.lblTerrain.Name = "lblTerrain"
        Me.lblTerrain.Size = New System.Drawing.Size(516, 41)
        Me.lblTerrain.TabIndex = 9
        Me.lblTerrain.Text = "This battle occurs in Hills (Light Woods)."
        '
        'cboActiveBattle
        '
        Me.cboActiveBattle.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cboActiveBattle.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.cboActiveBattle.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.cboActiveBattle.Location = New System.Drawing.Point(264, 48)
        Me.cboActiveBattle.Name = "cboActiveBattle"
        Me.cboActiveBattle.Size = New System.Drawing.Size(435, 28)
        Me.cboActiveBattle.TabIndex = 11
        Me.cboActiveBattle.Text = "<Select A Battle>"
        '
        'lblSelectBattle
        '
        Me.lblSelectBattle.BackColor = System.Drawing.Color.LightSteelBlue
        Me.lblSelectBattle.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblSelectBattle.Location = New System.Drawing.Point(8, 48)
        Me.lblSelectBattle.Name = "lblSelectBattle"
        Me.lblSelectBattle.Size = New System.Drawing.Size(255, 28)
        Me.lblSelectBattle.TabIndex = 12
        Me.lblSelectBattle.Text = "Select Battle"
        Me.lblSelectBattle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'basAttackerAssets
        '
        Me.basAttackerAssets.DefenderView = False
        Me.basAttackerAssets.Dock = System.Windows.Forms.DockStyle.Top
        Me.basAttackerAssets.GameData = Nothing
        Me.basAttackerAssets.Location = New System.Drawing.Point(0, 0)
        Me.basAttackerAssets.Name = "basAttackerAssets"
        Me.basAttackerAssets.Size = New System.Drawing.Size(312, 184)
        Me.basAttackerAssets.TabIndex = 13
        '
        'pnlAssets
        '
        Me.pnlAssets.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.pnlAssets.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlAssets.Controls.Add(Me.basDefenderAssets)
        Me.pnlAssets.Controls.Add(Me.splAssetSplitter)
        Me.pnlAssets.Controls.Add(Me.basAttackerAssets)
        Me.pnlAssets.Location = New System.Drawing.Point(8, 224)
        Me.pnlAssets.Name = "pnlAssets"
        Me.pnlAssets.Size = New System.Drawing.Size(312, 376)
        Me.pnlAssets.TabIndex = 15
        '
        'basDefenderAssets
        '
        Me.basDefenderAssets.DefenderView = True
        Me.basDefenderAssets.Dock = System.Windows.Forms.DockStyle.Fill
        Me.basDefenderAssets.GameData = Nothing
        Me.basDefenderAssets.Location = New System.Drawing.Point(0, 190)
        Me.basDefenderAssets.Name = "basDefenderAssets"
        Me.basDefenderAssets.Size = New System.Drawing.Size(312, 186)
        Me.basDefenderAssets.TabIndex = 15
        '
        'splAssetSplitter
        '
        Me.splAssetSplitter.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.splAssetSplitter.Dock = System.Windows.Forms.DockStyle.Top
        Me.splAssetSplitter.Location = New System.Drawing.Point(0, 184)
        Me.splAssetSplitter.Name = "splAssetSplitter"
        Me.splAssetSplitter.Size = New System.Drawing.Size(312, 6)
        Me.splAssetSplitter.TabIndex = 14
        Me.splAssetSplitter.TabStop = False
        '
        'tmrRedrawBattlemap
        '
        Me.tmrRedrawBattlemap.Enabled = True
        Me.tmrRedrawBattlemap.Interval = 250
        '
        'ctlEndOfCombatPhase
        '
        Me.BackColor = System.Drawing.Color.Black
        Me.Controls.Add(Me.lblSelectBattle)
        Me.Controls.Add(Me.cboActiveBattle)
        Me.Controls.Add(Me.pnlArea)
        Me.Controls.Add(Me.pnlSelectedBattle)
        Me.Controls.Add(Me.pnlCombatsTitle)
        Me.Controls.Add(Me.pnlAssets)
        Me.Name = "ctlEndOfCombatPhase"
        Me.Size = New System.Drawing.Size(707, 608)
        Me.pnlCombatsTitle.ResumeLayout(False)
        Me.pnlSelectedBattle.ResumeLayout(False)
        CType(Me.picBattleArea, System.ComponentModel.ISupportInitialize).EndInit()
        Me.pnlArea.ResumeLayout(False)
        Me.pnlAssets.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Property MapBMP() As Bitmap
        Get
            Return ptrMapBmp
        End Get
        Set(ByVal Value As Bitmap)
            ptrMapBmp = Value
        End Set
    End Property

    Public Property MapData() As FMPLib01.FlexMapData
        Get
            Return m_MapData
        End Get
        Set(ByVal Value As FMPLib01.FlexMapData)
            m_MapData = Value
        End Set
    End Property

    Public Property GameData() As CampaignerGameData
        Get
            Return ptrGameData
        End Get
        Set(ByVal Value As CampaignerGameData)
            Try
                ptrGameData = Value
                ListCombats()
                basAttackerAssets.GameData = Value
                basDefenderAssets.GameData = Value
            Catch ex As Exception
                HandleException("ctlEndOfCombatPhase", ex)
            End Try
        End Set
    End Property

    Private Sub ListCombats()
        Dim batt As Battle
        Dim battkey As String

        cboActiveBattle.Items.Clear()

        If ptrGameData Is Nothing Then Exit Sub

        If ptrGameData.Battles_g.HT.Count = 0 Then Exit Sub

        Try
            For Each battkey In ptrGameData.Battles_g.HT.Keys
                batt = ptrGameData.Battles_g.Item(battkey)
                cboActiveBattle.Items.Add(batt)
            Next

            cboActiveBattle.SelectedIndex = 0
            ptrSelectedBattle = cboActiveBattle.SelectedItem
            SelectBattle()

            ''// populate the properties for the battle. Units, etc in the the lower boxies.
            PopulateProperties()
        Catch ex As Exception
            HandleException(Me.Name, ex)
        End Try

    End Sub

    Private Sub PopulateProperties()

        Try
            '// show the battle result
            Select Case ptrSelectedBattle.BattleResult
                Case cmplib01.BattleResult_cgd.NotFinished : Me.optUnresolved.Checked = True
                Case cmplib01.BattleResult_cgd.AttackerVictory : Me.optAttackerVictory.Checked = True
                Case cmplib01.BattleResult_cgd.AttackerMarginalVictory : Me.optAttackerMarginalVictory.Checked = True
                Case cmplib01.BattleResult_cgd.DefenderVictory : Me.optDefenderVictory.Checked = True
                Case cmplib01.BattleResult_cgd.DefenderMarginalVictory : Me.optDefenderMarginalVictory.Checked = True
                Case cmplib01.BattleResult_cgd.Draw : Me.optDraw.Checked = True
            End Select

            '// list the chits involved
            ListChits()

        Catch ex As Exception
            HandleException("ctlEndOfCombatPhase.PopulateProperties", ex)
        End Try
    End Sub

    Private Sub ListChits()
        Try
            basAttackerAssets.SelectedBattle = ptrSelectedBattle

            basDefenderAssets.DefenderView = True
            basDefenderAssets.SelectedBattle = ptrSelectedBattle

        Catch ex As Exception
            HandleException("ctlEndOfCombatPhase.ListChits", ex)
        End Try
    End Sub

    Private Sub SelectBattle()
        ' show the battle name
        Try
            If m_MapData Is Nothing Then Exit Sub

            lblCombatName.Text = ptrSelectedBattle.BattleName
            ' show the battle result
            Select Case ptrSelectedBattle.BattleResult
                Case BattleResult_cgd.NotFinished : optUnresolved.Checked = True
                Case BattleResult_cgd.AttackerVictory : optAttackerVictory.Checked = True
                Case BattleResult_cgd.AttackerMarginalVictory : optDefenderMarginalVictory.Checked = True
                Case BattleResult_cgd.DefenderVictory : optDefenderVictory.Checked = True
                Case BattleResult_cgd.DefenderMarginalVictory : optDefenderMarginalVictory.Checked = True
                Case BattleResult_cgd.Draw : optDraw.Checked = True
            End Select

            ' we need the terrain and a little picture. Maybe.
            CreateOverviewMap()
            ' we need to draw the units on the overview map too.
            DrawUnits()

            ListChits()

            ' terrain
            Dim terrainName As String
            Dim terrainDesc As String

            m_MapData.TerrainInfoAtCoord(ptrSelectedBattle.BattleLocation, terrainName, terrainDesc)
            lblTerrain.Text = "This battle occurs in " & terrainName & "."

            lblTerrainDescription.Text = terrainDesc
            lblDefensiveValue.Text = "Defensive Value: " & m_MapData.DefenseAtCoord(ptrSelectedBattle.BattleLocation)

            '// set names
            SetButtonNames()

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub SetButtonNames()
        Try
            Dim att As String = ptrGameData.Faction_g.Item("FACT" & ptrSelectedBattle.AttackingFactionID).FactionName
            Dim def As String = ptrGameData.Faction_g.Item("FACT" & ptrSelectedBattle.DefendingFactionID).FactionName

            Me.optAttackerBreakthrough.Text = att & " Breakthrough"
            Me.optAttackerMarginalVictory.Text = att & " Marginal Victory"
            Me.optAttackerVictory.Text = att & " Victory"

            Me.optDefenderBreakout.Text = def & " Breakout"
            Me.optDefenderMarginalVictory.Text = def & " Marginal Victory"
            Me.optDefenderVictory.Text = def & " Victory"

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub CreateOverviewMap()

        '// snags a portion of the mapbitmap and displays it for the user
        If ptrMapBmp Is Nothing Then Exit Sub

        '// find the area around the selected battle
        Dim g As Graphics = picBattleArea.CreateGraphics

        g.DrawImage(ptrMapBmp, New RectangleF(0, 0, picBattleArea.Width, picBattleArea.Height), New RectangleF(ptrSelectedBattle.BattleLocation.X - (picBattleArea.Width / 2), ptrSelectedBattle.BattleLocation.Y - (picBattleArea.Height / 2), picBattleArea.Width, picBattleArea.Height), GraphicsUnit.Pixel)

        '// we can draw our options too, like who is in support range and such
        g.Dispose()

    End Sub

    Private Sub DrawUnits()
        If ptrMapBmp Is Nothing Then Exit Sub

        Dim g As Graphics = picBattleArea.CreateGraphics

        'Dim chitKey As String
        'Dim chit As GroundChitType
        Dim imageindex As Integer
        Dim offSet As Point

        For Each mem As ChitMember In ptrSelectedBattle.InvolvedChits
            If mem.Status = GroundUnitStatus_cgd.Dead Then
                imageindex = 1
            Else
                If mem.UnitType = GroundChitClass_cgd.Objective Then
                    imageindex = 0
                Else
                    If mem.OwningFaction.FactionID = ptrSelectedBattle.DefendingFactionID Then
                        imageindex = 4
                    Else
                        imageindex = 2
                    End If
                End If
            End If
            offSet.X = mem.Location.X - ptrSelectedBattle.BattleLocation.X + picBattleArea.Width / 2
            offSet.Y = mem.Location.Y - ptrSelectedBattle.BattleLocation.Y + picBattleArea.Height / 2
            g.DrawImage(imlChitIcons.Images(imageindex), offSet)
        Next


        'For Each chitKey In ptrSelectedBattle.InvolvedChits.Keys
        '    chit = ptrSelectedBattle.InvolvedChits.Item(chitKey)
        '    If chit.Status = GroundUnitStatus_cgd.Dead Then
        '        imageindex = 1
        '    Else
        '        If chit.GroundChitClass = GroundChitClass_cgd.Objective Then
        '            imageindex = 0
        '        Else
        '            If chit.OwningFaction = ptrSelectedBattle.DefendingFactionID Then
        '                imageindex = 4
        '            Else
        '                imageindex = 2
        '            End If
        '        End If
        '    End If
        '    offSet.X = chit.Location.X - ptrSelectedBattle.BattleLocation.X + picBattleArea.Width / 2
        '    offSet.Y = chit.Location.Y - ptrSelectedBattle.BattleLocation.Y + picBattleArea.Height / 2
        '    g.DrawImage(imlChitIcons.Images(imageindex), offSet)
        'Next

        g.Dispose()

    End Sub

#Region "Set Result"

    Private Sub optUnresolved_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optUnresolved.CheckedChanged
        SetResult(BattleResult_cgd.NotFinished)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub optAttackerVictory_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAttackerVictory.CheckedChanged
        SetResult(BattleResult_cgd.AttackerVictory)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub optAttackerMarginalVictory_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAttackerMarginalVictory.CheckedChanged
        SetResult(BattleResult_cgd.AttackerMarginalVictory)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub optDraw_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optDraw.CheckedChanged
        SetResult(BattleResult_cgd.Draw)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub optDefenderVictory_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optDefenderVictory.CheckedChanged
        SetResult(BattleResult_cgd.DefenderVictory)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub optDefenderMarginalVictory_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optDefenderMarginalVictory.CheckedChanged
        SetResult(BattleResult_cgd.DefenderMarginalVictory)
        If sender.checked = True Then
            sender.BackColor = Color.DarkSeaGreen
        Else
            sender.backcolor = Color.DarkSalmon
        End If
    End Sub

    Private Sub SetResult(ByVal result As BattleResult_cgd)
        If ptrSelectedBattle Is Nothing Then Exit Sub

        ptrSelectedBattle.BattleResult = result

    End Sub

#End Region

    Private Sub btnApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnApply.Click

        If ValidateBattles() = True Then
            RaiseEvent ApplyCombatResults()
        End If

    End Sub

    Private Function ValidateBattles() As Boolean
        Dim batt As Battle
        Dim battKey As String
        Dim unresolved As Boolean = False

        For Each battKey In ptrGameData.Battles_g.HT.Keys
            batt = ptrGameData.Battles_g.Item(battKey)
            If batt.BattleResult = BattleResult_cgd.NotFinished Then
                unresolved = True
                Exit For
            End If
        Next

        If unresolved = True Then
            If MessageBox.Show("Some battles do not have a result set, if you continue, they will be set to draw. Do you wish to continue?", "Apply Results", MessageBoxButtons.YesNo) = DialogResult.Yes Then
                SetUnresolvedToDraw()
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function

    Private Sub SetUnresolvedToDraw()
        Dim batt As Battle
        Dim battKey As String

        For Each battKey In ptrGameData.Battles_g.HT.Keys
            batt = ptrGameData.Battles_g.Item(battKey)
            If batt.BattleResult = BattleResult_cgd.NotFinished Then
                batt.BattleResult = BattleResult_cgd.Draw
            End If
        Next
    End Sub

    Private Sub cboActiveBattle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboActiveBattle.SelectedIndexChanged
        If cboActiveBattle.SelectedItem Is Nothing Then Exit Sub
        ptrSelectedBattle = cboActiveBattle.SelectedItem
        SelectBattle()
    End Sub

    Private Sub basAttackerAssets_ChitChangedOwnership() Handles basAttackerAssets.ChitChangedOwnership, basDefenderAssets.ChitChangedOwnership
        basAttackerAssets.RefreshList()
        basDefenderAssets.RefreshList()
    End Sub

    Private Sub basAttackerAssets_UnitKilledOrUnkilled() Handles basAttackerAssets.UnitKilledOrUnkilled, basDefenderAssets.UnitKilledOrUnkilled
        CreateOverviewMap()
        DrawUnits()

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Try
            CreateOverviewMap()
            DrawUnits()
        Catch ex As Exception
            HandleException(Me.Name, ex)
        End Try
    End Sub

    Private Sub tmrRedrawBattlemap_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrRedrawBattlemap.Tick
        Try
            CreateOverviewMap()
            DrawUnits()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnCombatSummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCombatSummary.Click
        Dim fsumm As New frmBattlesListing
        fsumm.ShowDialog(ptrGameData, m_MapData)
        fsumm.Dispose()

    End Sub
End Class


